/* GUI CONVERTED from rscup.i (converter v1.76) Thu Apr 25 19:01:17 2002 */
/* rscup.i - Release Management Supplier Schedules                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.3.1.3 $                                                       */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 7.4    LAST MODIFIED: 10/01/93           BY: WUG *H148*          */
/* REVISION: 7.4    LAST MODIFIED: 03/31/97     BY: *H0VZ* Suresh Nayak       */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98     BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.3.1.3 $   BY: Jean Miller        DATE: 04/16/02  ECO: *P05H*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* SHIPPING SUMMARY REPORT INCLUDE */

/*
{1} = break by
{2} = lowest break by field above tr_trnbr
*/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

define shared variable supplier_from like po_vend.
define shared variable supplier_to like po_vend.
define shared variable shipto_from like po_ship.
define shared variable shipto_to like po_ship.
define shared variable part_from like pod_part.
define shared variable part_to like pod_part.
define shared variable po_from like po_nbr.
define shared variable po_to like po_nbr.
define shared variable buyer_from like po_buyer.
define shared variable buyer_to like po_buyer.
define shared variable update_yn like mfc_logical.
define shared variable cum_ship_start_dt as date.
define shared variable Remarks as character format "x(24)".

define buffer poddet for pod_det.

define variable cum_qty as decimal.
define variable reduction_amt as decimal.
define variable left_to_apply as decimal.

for each po_mstr no-lock
   where po_nbr >= po_from and po_nbr <= po_to
     and po_vend >= supplier_from and po_vend <= supplier_to
     and po_buyer >= buyer_from and po_buyer <= buyer_to
     and po_sched,
    each pod_det no-lock
   where pod_nbr = po_nbr
     and pod_sched
     and pod_part >= part_from and pod_part <= part_to
     and pod_site >= shipto_from and pod_site <= shipto_to
     and pod_nbr >= po_from and pod_nbr <= po_to
      {1}:

   display
      po_nbr
      pod_line
      pod_part
      po_vend
      pod_site
      po_buyer
      pod_cum_qty[1]
   with frame detail STREAM-IO /*GUI*/ .

   down 1 with frame detail.

   if update_yn then do:
      cum_qty = pod_cum_qty[1].

      create tr_hist.
      assign
         tr_date      = today
         tr_effdate   = today
         tr_part      = pod_part
         tr_type      = "CUM-RRES"
         tr_nbr       = pod_nbr
         tr_line      = pod_line
         tr_addr      = po_vend
         tr_program   = execname
         tr_time      = time
         tr_loc_begin = 0
         tr_rmks      = Remarks
         tr_userid    = global_userid
         tr_qty_chg   = - pod_cum_qty[1].

      {mfntran.i}

      do for poddet:
         find poddet where recid(poddet) = recid(pod_det) exclusive-lock.
         assign
            pod_cum_qty[1]  = 0
            pod_cum_date[1] = cum_ship_start_dt.
      end.

      /* GO INTO CURRENT SCHEDULE AND REDUCE REQUIREMENTS BY CUM RECEIVED */
      left_to_apply = cum_qty.

      find sch_mstr where sch_type = 4
         and sch_nbr = pod_nbr
         and sch_line = pod_line
         and sch_rlse_id = pod_curr_rlse_id[1]
      exclusive-lock no-error.

      if available sch_mstr then do:
         reduction_amt = min(sch_pcr_qty, left_to_apply).
         sch_pcr_qty = sch_pcr_qty - reduction_amt.
         left_to_apply = left_to_apply - reduction_amt.

         for each schd_det exclusive-lock
            where schd_type = sch_type
              and schd_nbr = sch_nbr
              and schd_line = sch_line
              and schd_rlse_id = sch_rlse_id
         while left_to_apply > 0:
            reduction_amt = min(schd_discr_qty, left_to_apply).
            schd_discr_qty = schd_discr_qty - reduction_amt.
            left_to_apply = left_to_apply - reduction_amt.
         end.

         /* RECALCULATE CUMS */
         cum_qty = sch_pcr_qty.

         for each schd_det exclusive-lock
            where schd_type = sch_type
              and schd_nbr = sch_nbr
              and schd_line = sch_line
              and schd_rlse_id = sch_rlse_id:
            cum_qty = cum_qty + schd_discr_qty.
            schd_cum_qty = cum_qty.
         end.

      end.

      {gprun.i ""rsmrw.p"" "(input pod_nbr, input pod_line, input yes)"}

   end.

   
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


end.
